package cn.lixin.order.controller;

import cn.lixin.basic.utils.AjaxResult;
import cn.lixin.basic.utils.LoginContext;
import cn.lixin.basic.utils.PageList;
import cn.lixin.order.domain.AdoptOrder;
import cn.lixin.order.domain.PetAcquisitionOrder;
import cn.lixin.order.query.AdoptOrderQuery;
import cn.lixin.order.query.PetAcquisitionOrderQuery;
import cn.lixin.order.service.IAdoptOrderService;
import cn.lixin.order.service.IPetAcquisitionOrderService;
import cn.lixin.order.service.IProductOrderService;
import cn.lixin.user.domain.Logininfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@RestController
@RequestMapping("/adoptOrder")
public class AdoptOrderController {
    @Autowired
    private IAdoptOrderService adoptOrderService;
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){
        try{
            Logininfo currentLoginInfo = LoginContext.getCurrentLoginInfo(request);
            String payData = adoptOrderService.submit(params, currentLoginInfo); // <form name="p……;</script>
            return AjaxResult.me().setResultObj(payData);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("下单失败！"+e.getMessage());
        }

    }
    // 店铺高级查询
    @PostMapping("/admin")
    public PageList<AdoptOrder> admin(@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        return adoptOrderService.admin(query,LoginContext.getCurrentLoginInfo(request));
    }
    // 用户高级查询
    @PostMapping("/user")
    public PageList<AdoptOrder> user(@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        return adoptOrderService.user(query,LoginContext.getCurrentLoginInfo(request));
    }

    // 后台根据orderId 查询order
    @GetMapping("/{id}")
    public AdoptOrder getInfo(@PathVariable("id") Long orderId){
        return adoptOrderService.loadById(orderId);
    }



}
